<!--
 * @Author: lh
 * @Date: 2023-07-11 13:52:31
 * @LastEditors: lh
 * @LastEditTime: 2024-03-08 10:42:07
-->
<template>
  <div>
    <!-- :searchDataList="searchDataListJy" -->
    <!-- <personnel></personnel> -->
    <tabCom
      @Refresh="Refresh"
      @search-callback="searchCallback"
      :title="'试卷模块管理'"
      :operation-api="operationApiA"
      :table-data-rule="tableDataRuleA"
      :search-data-list="searchDataListJy"
      :needPagination="true"
      :update_show_key="'id'"
      :update_show_value="[0]"
      :formDataWidth="'30%'"
      :isShowDownLoadFile="true"
      :showSearch="true"
      :addButtonList="addButtonList"
      @buttonMoudle="buttonMoudle"
      :creationShowTime="false"
      :UploadArrMerge="true"
      :isAddArr="false"
      :setAddHeaders="{ 'Content-Type': 'multipart/form-data' }"
      ref="tabCombox"
    >
      <template #add="{ formData, currentUpdateId }">
        <el-form-item :label="item.title" v-for="(item, index) in searchDataListJyEdit" :key="index">
          <el-input
            v-if="!item.type && ((currentUpdateId && item.isEdit) || (!currentUpdateId && item.isAdd))"
            v-model="formData[item.name]"
            placeholder="请输入"
          />
          <upfilebox
            v-else-if="item.type == 'file' && ((currentUpdateId && item.isEdit) || (!currentUpdateId && item.isAdd))"
            fileType="file"
            :maxNum="maxNum"
            v-model="formData[item.name]"
            v-model:name="formData[item.prop]"
            v-model:filecatch="formData[item.filecatch]"
          ></upfilebox>
          <div v-else style="color: #999">无需操作~</div>
        </el-form-item>
      </template>
    </tabCom>
    <!-- 审核 -->
    <el-dialog v-model="dialogVisible" :title="'发布审核'" @close="resetForm" width="30%">
      <el-form ref="formRef" label-width="100px" label-position="left">
        <el-form-item prop="examinationState" label="审核状态">
          <el-radio-group v-model="examinationState">
            <el-radio :label="1" size="large">同意</el-radio>
            <el-radio :label="2" size="large">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleCreate">确认</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import tabCom from "@/components/table/indexcopy.vue"
// import { gethomeStatistics } from "@/api/home/index"
import { ref, onMounted, reactive } from "vue"
import upfilebox from "@/components/table/upfile.vue"
import personnel from "@/components/table/personnel.vue"
import { useUserStoreHook } from "@/store/modules/user"
import { ElMessage, ElMessageBox } from "element-plus"
import { examinationEffectiveRelease } from "@/api/procedure"
import router from "@/router"

const { userId } = useUserStoreHook()
const tabCombox = ref<typeof tabCom>()

onMounted(() => {
  init()
})
// 接口请求配置
const operationApiA = ref<any>([
  { type: "add", interface: "/userExam/importData" },
  { type: "update", interface: "/userExam/insertOrUpdate" },
  { type: "search", interface: "/userExam/selectAll" },
  { type: "delete", interface: "/userExam/deleteByIds" },
  { type: "svg", interface: "/userExam/downloadTemplate" }
])
//#region  添加按钮所有逻辑
// 添加按钮
const addButtonList = [
  { name: "编辑试卷", type: "infill" },
  { name: "预览试卷", type: "validation" }
]
const tablerow = ref() // 当前操作表单数据
// 按钮回调
const buttonMoudle = (type: string, row: any, Face: string) => {
  tablerow.value = row
  // console.log(type, row, "-*-buttonMoudle")
  switch (type) {
    case "infill": // 编辑试卷
      // infillFn()
      console.log(row, "--row--")
      // debugger;
      router.push({
        // path:"/examinationModle_details?id="+row.id
        path: "/examinationModle_details",
        query: {
          id: row.id,
          name: row.examName
        }
      })
      break
    case "validation": // 预览试卷
      // infillFn()
      router.push({
        // path:"/examinationModle_details?id="+row.id
        path: "/examination",
        query: {
          id: row.id,
          name: row.examName,
          examId: row.examId,
          isExamination: "0"
        }
      })
      break
  }
}
let dialogVisible = ref(false) // 用户审查程序文件弹框
let actionItemEvolve = ref("") // 行动项进展
let examinationState = ref(1) // 选择

// 用户审查程序文件弹框 方法
const infillFn = () => {
  // console.log("infillFn", userId)
  if (tablerow.value.effectiveReleaseState == 6) {
    ElMessage.error("已完成~")
    return
  }
  dialogVisible.value = true
}
// 重置数据
const resetForm = () => {
  actionItemEvolve.value = ""
}
// 确认反馈
const handleCreate = () => {
  console.log("actionItemEvolve", actionItemEvolve.value)

  examinationEffectiveRelease({
    id: tablerow.value.id,
    effectiveReleaseState: examinationState.value == 1 ? tablerow.value.effectiveReleaseState : 5
  }).then((res) => {
    console.log(res, "---res")

    if (res.code == 200) {
      ElMessage({ message: "提交成功", type: "success" })
      tabCombox.value.resetSearch()
      dialogVisible.value = false
      resetForm()
    }
  })
}

//#endregion

// 搜索配置
const searchDataListJy = [
  { name: "id", title: "试卷id" },
  { name: "examName", title: "试卷名称" },
  { name: "standardScore", title: "达标分数" }
]
// 添加配置
const searchDataListJyEdit = [
  // { name: "examName", title: "试卷名称" },
  {
    name: "aaaaaa",
    title: "上传试卷",
    type: "file",
    prop: "examName",
    filecatch: "file",
    isEdit: false,
    isAdd: true
  },
  { name: "examName", title: "试卷名称", isEdit: true, isAdd: false },
  { name: "standardScore", title: "达标分数", isEdit: true, isAdd: true },

  { name: "remarks", title: "备注", isEdit: true, isAdd: true }
]
// 表单配置
const tableDataRuleA = ref([
  { prop: "id", label: "id" },
  { prop: "examName", label: "试卷名称" },
  { prop: "standardScore", label: "达标分数" },
  { prop: "remarks", label: "备注" }
  // {prop: 'operate',label: '操作'},
])
// 初始化
const init = () => {}
// 表单刷新
const Refresh = () => {
  //用户数据概览
}
// 搜索回调
const searchCallback = (search: any) => {}
const loading = ref<boolean>(false)
const gailan = ref<any>({})
const gethomeStatisticsStar = (obj: any = {}) => {
  // loading.value = true
  // gethomeStatistics(obj).then((res: any) => {
  //   gailan.value = res.data
  //   loading.value = false
  // })
}

// 时间选择限定范围
const chooseTimeChange = (time: any) => {
  const starTime = JSON.parse(JSON.stringify(time[0]))
  const endTime = JSON.parse(JSON.stringify(time[1]))
  const minTime = new Date(insertStr(insertStr(starTime, 4, "-"), 7, "-")).getTime()
  const maxTime = new Date(insertStr(insertStr(endTime, 4, "-"), 7, "-")).getTime()
  const allow = 2592000000 //30天
  if (maxTime - minTime > allow) {
    ElMessage.warning("选择范围请在30天以内!")
    chaxunState.value = false
  } else {
    chaxunState.value = true
  }
}
</script>
<style scoped lang="scss">
.search-wrapper {
  margin: 0 auto;
  width: 98.5%;
  margin-top: 10px;
}
</style>
